//
//  CustomButton.m
//  VTravel
//
//  Created by lanouhn on 16/8/3.
//  Copyright © 2016年 xiaoYu. All rights reserved.
//

#import "CustomButton.h"

@implementation CustomButton

/** 自定义Button的初始化方法 */
- (instancetype)initWithFrame:(CGRect)frame imageName:(NSString *)imageNameStr LabelTitle:(NSString *)titleStr{
    if (self = [super initWithFrame:frame]) {
        // 创建图片对象
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, frame.size.width, frame.size.width)];
        imageView.image = [UIImage imageNamed:imageNameStr];
        imageView.layer.cornerRadius = frame.size.width / 2;
        imageView.layer.masksToBounds = YES;
        
        [self addSubview:imageView];
        
        // 创建label
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(- KButtonSpace / 2, frame.size.width + 15, frame.size.width + KButtonSpace, frame.size.height - frame.size.width - 15)];
        label.text = titleStr;
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:15];
        [self addSubview:label];
        
    }
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame imageNameUrl:(NSString *)imgUrl LBTitleStr:(NSString *)titleStr{
    if (self = [super initWithFrame:frame]) {
        // 创建图片对象
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, frame.size.width, frame.size.width)];
        [imageView sd_setImageWithURL:[NSURL URLWithString:imgUrl]];
        imageView.layer.cornerRadius = frame.size.width / 2;
        imageView.layer.masksToBounds = YES;
        
        [self addSubview:imageView];
        
        // 创建label
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(- KButtonSpace / 2, frame.size.width + 15, frame.size.width + KButtonSpace, frame.size.height - frame.size.width - 15)];
        label.text = titleStr;
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:15];
        [self addSubview:label];
        
    }
    return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
